package com.example.demo.web.controller;

import com.example.demo.pojo.SysUser;
import com.example.demo.service.UserService;
import com.example.demo.vo.ResultData;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@Api(tags = "用户")
@RestController
@RequestMapping("users")
public class UserController {
    // RestFul
    @Autowired
    UserService userService;

    @RequestMapping("/index")
    public String index(){
        return "index";
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(String username, String password, Model model) {
//        try {
//            Subject subject = SecurityUtils.getSubject();
//            UsernamePasswordToken token = new UsernamePasswordToken(username, password);
//            subject.login(token);
//        } catch (UnknownAccountException e) {
//            e.printStackTrace();
//            model.addAttribute("msg","用户名不存在");
//            return "error";
//        } catch (IncorrectCredentialsException e){
//            e.printStackTrace();
//            model.addAttribute("msg","密码输入错误");
//            return "error";
//        }
        return "success";
    }

    @GetMapping("test")
    public String test(){
        return "hhhhh";
    }



//    @ApiOperation(value = "登录",notes = "注意事项")
//    @PostMapping("login")
//    public User login(String username, String password){
//        return userService.login(username,password);
//    }
//    //1,依赖   2.配置文件   3.conrtoller上加注解    4.访问并测试
//
//    @ApiOperation(value = "添加")
//    @PostMapping
//    public ResultData addUser(@RequestBody User user){
//        boolean b = userService.addUser(user);
//        return ResultData.success(b);
//    }
//
//    @ApiOperation(value = "修改")
//    @PutMapping
//    public ResultData updateUser(@RequestBody User user){
//        boolean b = userService.addUser(user);
//        return ResultData.success(b);
//    }
//
//    //@RequestMapping(value = "{id}",method = RequestMethod.GET)
//    @GetMapping("{id}")
//    public ResultData getUser(@PathVariable Integer id,@CookieValue String a){
//        return null;
//    }
//
//    @GetMapping()
//    public ResultData getAllUser(@RequestHeader(name = "abc") String abc){
//        return ResultData.success(abc);
//    }
//
//
//    @DeleteMapping("{id}")
//    public ResultData deleteUser(@PathVariable Integer id, String name){
//        return null;
//    }

    // path  query body headers  form/data


    //java中的接口     interface
    //提供对外访问的接口

    @GetMapping("{id}")
    public ResultData getUserById(@PathVariable Long id) {
        SysUser sysUser = userService.getUserById(id);
        return ResultData.success(sysUser);
    }


    @GetMapping
    public void getAllUser(@PathVariable Long id) {
    }

    @PostMapping
    public void insert(SysUser sysUser) {
    }

    @PutMapping
    public void update(SysUser sysUser) {
    }

    @DeleteMapping
    public void delete(Long id) {
    }

}
